package com.feature.shop.user.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import com.feature.core.domain.PageVo;
import com.feature.core.domain.Response;
import com.feature.shop.auth.api.vo.LoginUserVo;
import com.feature.shop.core.util.ShopApplictionContext;
import com.feature.shop.user.api.ShopMenuApi;
import com.feature.shop.user.api.request.AddMenuRequest;
import com.feature.shop.user.api.request.DelMenuRequest;
import com.feature.shop.user.api.request.ShopMenuListRequest;
import com.feature.shop.user.api.request.ShopMenuPageRequest;
import com.feature.shop.user.api.request.UpdateMenuRequest;
import com.feature.shop.user.api.vo.ShopMenuVo;
import com.feature.shop.user.api.vo.ShopTreeMenuVo;
import com.feature.shop.user.service.ShopMenuService;

import jakarta.validation.Valid;

/***
 * 菜单表Controller
 */
@RestController
public class ShopMenuController implements ShopMenuApi {

    @Autowired
    private ShopMenuService shopMenuService;

    /**
     * 分页查询
     * 
     * @param request
     * @return
     */
    public Response<PageVo<ShopMenuVo>> getMenuPageList(@Valid ShopMenuPageRequest req) {
        PageVo<ShopMenuVo> result = shopMenuService.findPageList(req);
        return Response.ok(result);
    }

    /**
     * list查询
     * 
     * @param request
     * @return
     */
    public Response<List<ShopMenuVo>> getMenuList(@Valid ShopMenuListRequest req) {
        return Response.ok(shopMenuService.findList(req));
    }

    public Response<List<ShopTreeMenuVo>> getAuthMenuList() {
        LoginUserVo loginUser = ShopApplictionContext.getLoginUser();
        return Response.ok(shopMenuService.getAuthMenuList(loginUser));
    }

    public Response<List<ShopTreeMenuVo>> getMenuTreeList() {
        LoginUserVo loginUser = ShopApplictionContext.getLoginUser();
        return Response.ok(shopMenuService.getMenuTreeList(loginUser));
    }

    public Response<Map<String, Boolean>> getUserMenuAuth(Integer userId) {
        return Response.ok(shopMenuService.getUserMenuAuth(userId));
    }

    public Response<Integer> addMenu(@Valid AddMenuRequest addMenuRequest) {
        LoginUserVo loginUser = ShopApplictionContext.getLoginUser();
        return Response.ok(shopMenuService.addMenu(addMenuRequest, loginUser));
    }

    @Override
    public Response<?> updateMenu(@Valid UpdateMenuRequest req) {
        LoginUserVo loginUser = ShopApplictionContext.getLoginUser();
        shopMenuService.updateMenu(req, loginUser);
        return Response.ok();
    }

    @Override
    public Response<?> delMenu(@Valid DelMenuRequest req) {
        LoginUserVo loginUser = ShopApplictionContext.getLoginUser();
        shopMenuService.delMenu(req, loginUser);
        return Response.ok();
    }

}
